using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace smartBrowser.Util
{
    public class SwoogleSearchService
    {
        public static List<Uri> Query(string query)
        {
            List<Uri> links = new List<Uri>();

            try
            {
                string contents = WebPageFetcher.FecthPage(new Uri("http://swoogle.umbc.edu/index.php?service=search&queryType=search_swd_ontology&searchString=" + query.Trim().Replace(' ', '+')));
                String expression = "<a class=\"external\" href=\"(.*?)\">(.*?)</a>";
                Regex regex = new Regex(expression);
                MatchCollection matches = regex.Matches(contents);
                
                foreach (Match match in matches)
                {
                    links.Add(new Uri(match.Groups[1].Value));
                }                

            }
            catch (Exception exception)
            {
                Console.Out.WriteLine("Error in Swoogle Search Service: "+exception.Message);
            }

            return links;
        }
    }
}
